#ifndef TOASTWIDGET_H
#define TOASTWIDGET_H

#include <QColor>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
#include <QTimer>
#include <QWidget>

class EzToastWidget : public QWidget {
    Q_OBJECT

public:
    static EzToastWidget* instance();

    void showMessage(const QString& message, int duration = 3000, bool autoClose = true);
    void setIcon(const QPixmap& icon);
    void setBackgroundColor(const QColor& color);
    void setBorderColor(const QColor& color);
    void setFontColor(const QColor& color);

    void updatePosition(const QRect& targetRect);

protected:
    void mousePressEvent(QMouseEvent* event) override;
    void resizeEvent(QResizeEvent* event) override;
    void paintEvent(QPaintEvent* event) override;

private slots:
    void closeToast();

private:
    explicit EzToastWidget(QWidget* parent = nullptr);
    EzToastWidget& operator=(const EzToastWidget&) = delete;
    EzToastWidget(const EzToastWidget&) = delete;
    void fadeIn();
    void fadeOut();
    void applyLabelStyle();

private:
    QLabel* m_label;
    QLabel* m_iconLabel;
    QPushButton* m_closeButton;
    QTimer* m_timer;
    QColor m_backgroundColor;
    QColor m_borderColor;
    QColor m_fontColor;
    QRect m_showRect;
};

#endif  // TOASTWIDGET_H
